package be.bonamis.umpire.ui.client;

import java.util.logging.Logger;

import be.bonamis.umpire.ui.client.activities.BootActivity;
import be.bonamis.umpire.ui.client.activities.DispoActivity;
import be.bonamis.umpire.ui.client.activities.HistoryActivity;
import be.bonamis.umpire.ui.client.activities.LoginActivity;
import be.bonamis.umpire.ui.client.activities.QuizActivity;
import be.bonamis.umpire.ui.client.activities.WhoActivity;
import be.bonamis.umpire.ui.client.places.BootPlace;
import be.bonamis.umpire.ui.client.places.DispoPlace;
import be.bonamis.umpire.ui.client.places.HistoryPlace;
import be.bonamis.umpire.ui.client.places.LoginPlace;
import be.bonamis.umpire.ui.client.places.QuizPlace;
import be.bonamis.umpire.ui.client.places.WhoPlace;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.google.inject.Inject;

public class AppActivityMapper implements ActivityMapper {

	private final ClientFactory clientFactory;

	private final Logger LOGGER = Logger.getLogger("ActivityMapper");

	@Inject
	public AppActivityMapper(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
	}

	@Override
	public Activity getActivity(Place place) {
		LOGGER.info("Received place change in ActivityManager: " + place.toString());
		if (place instanceof LoginPlace) {
			return new LoginActivity((LoginPlace) place, clientFactory);
		} else {
			if (place instanceof BootPlace) {
				return new BootActivity((BootPlace) place, clientFactory);
			} else if (place instanceof DispoPlace) {
				return new DispoActivity((DispoPlace) place, clientFactory);
			} else if (place instanceof WhoPlace) {
				return new WhoActivity((WhoPlace) place, clientFactory);
			} else if (place instanceof QuizPlace) {
				return new QuizActivity((QuizPlace) place, clientFactory);
			} else if (place instanceof HistoryPlace) {
				return new HistoryActivity((HistoryPlace) place, clientFactory);
			}
		}

		return null;
	}
}
